package com.lzz.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author zhenzhen
 * @date 2018-12-17 上午10:20
 */
@WebFilter(urlPatterns = "/*")
@Order(2)
@Slf4j
public class MyFilter2 implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("=======[初始化:] 自定义过滤器MyFilter2=======");
    }

    @Override
    public void destroy() {
        log.info("=======[销毁:] 自定义过滤器MyFilter2=======");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        long start = System.currentTimeMillis();
        filterChain.doFilter(servletRequest, servletResponse);
        long end = System.currentTimeMillis();
        log.info("========[执行：] MyFilter2-过滤器耗时" + (end-start) + ";  URI:" + ((HttpServletRequest) servletRequest).getRequestURI());
    }
}
